<? 
	include('base.php');
	User::protect();
	include_class('venues');
	include_class('locations');
	include_class('band_members');
	include_class('band_information');
	$section = 'venues';
	if ($_POST['submit']) { 
		// add news entry
		$ve = Venue::add($_POST);
		if (!db::isError($ve)) {
			header('Location: venue_edit.php?id=' . $ve->getID());
		}
	}	
	
	$bi = BandInformation::get();
	//$defaultStateProvince = ($bi->getDefaultStateProvince()) ? $bi->getStateProvince() : VENUE_DEFAULT_STATEPROVINCE;
	//$defaultCity = ($bi->getDefaultCity()) ? $bi->getDefaultCity() : VENUE_DEFAULT_CITY;
	
	$defaultStateProvince = $bi->getDefaultStateProvince();
	$defaultCity = $bi->getDefaultCity();
	
	$editors = array('directions');
	$page_title = 'Add Venue';
	include('layout/header.php');

?>

<div id="breadcrumb">
	<a href="index.php">Audition &#62;</a>
	<a href="live.php">Live &#62;</a>
	<a href="venues.php">Venues &#62;</a>
	Add Venue
</div>
<? if (db::isError($ve)) {
	$ve->outputList();
}
?>
	<h1>new entry:</h1>
	<div class="inset">
	<form id="add_new_entry" action="<?=$PHP_SELF?>" method="post">
	<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
	<tr>
		<td width="50%"><strong>Name</strong><br/><input type="text" name="name" class="text" value="<?=$_POST['name']?>"></td>
		<td width="50%"><strong>Poster</strong><br/>		
		<? if (User::isAdmin()) { ?>
			<select name="user_id">
				<?
				$ul = new UserList();
				$uArray = $ul->getActiveAdminUsers();
				foreach ($uArray as $uo) { ?>
					<option class="admin-user" value="<?=$uo->getID()?>"<? if ($_POST['user_id'] == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?></option>
				<? }
				
				$bmlist = new BandMemberList();
				$bmarray = $bmlist->get_active_band_members();
				foreach ($bmarray as $bm) {
					$uo = $bm->getUserObject();
				?>
					<option value="<?=$uo->getID()?>"<? if ($_POST['user_id'] == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?></option>
				<? } ?>
			</select>

		<? } else { 
			$uo = User::getCurrent();
			echo($uo->getFirstName());
		} ?>
		
		</td>
	</tr>
	<tr>
		<td width="50%"><strong>Address 1</strong><br/><input type="text" class="text"name="address1" value="<?=$_POST['address1']?>"></td>
		<td width="50%"><strong>Address 2</strong><br/><input type="text" class="text" name="address2" value="<?=$_POST['address2']?>">
		</td>
	</tr>
	</table>
	<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
	<tr>
		<td width="33%"><strong>City</strong><br/><input type="text" name="city" value="<?=$defaultCity?>"></td>
		<td width="34%"><strong>State/Province</strong><br/>
		<select id="stateProvince" name="stateProvince" onchange="toggleOther(this)">
		<? $sl = new StateList();
		$stateList = $sl->getStates();
		$selected = false;
		foreach ($stateList as $key => $sp) {
			echo("<option value=\"" . $key . "\"");
			if ($_POST['stateProvince'] == $key || (!$_POST['stateProvince'] && $key == $defaultStateProvince)) {
				$selected = true;
				echo(" selected");
			}
			echo(">" . $sp . "</option>\r");
		} 
		echo("<option value=\"??\"");
		if (!$selected) { 
			echo(" selected");
		}
		echo(">** OTHER</option>");
		?>
		</select>
		</td>
		<td width="33%"><strong>If Other:</strong><br/><input <? if ($selected) { ?> disabled <? } ?> type="text" name="stateProvinceOther" value="<? if (!$selected) { ?><?=$_POST['stateProvinceOther']?><? } ?>"></td>
	</tr>
	<tr>
		<td><strong>Zip/Postal Code</strong><br/><input type="text" name="postalCode" value="<?=$_POST['postalCode']?>"></td>
		<td><strong>Country</strong><br/>
		<select id="country" name="country">
		<? $sl = new CountryList();
		$countryList = $sl->getCountries();
		$selected = false;
		foreach ($countryList as $key => $co) {
			echo("<option value=\"" . $key . "\"");
			if ($_POST['country'] == $key) {
				$selected = true;
				echo(" selected");
			}
			echo(">" . $co . "</option>\r");
		} 
		?>
		</select>
		</td>
		<td>&nbsp;</td>
	</tr>
	</table>
	<div class="edit-form"><strong>Directions</strong><br/>
		<textarea name="directions" id="directions" class="mid"><?=$_POST['directions']?></textarea>
	</div>
	<div class="edit-form">
		<input type="submit" value="Add Venue" class="button" name="submit">
		<input type="submit" value="Exit Without Adding" class="button" name="preview" onclick="location.href='venues.php'; return false">
	</div>
	
	<script type="text/javascript">
		function toggleOther(sp) {
			if (sp.value == "??") { 
				document.forms[0].stateProvinceOther.disabled = false;
			} else {
				document.forms[0].stateProvinceOther.disabled = true;
				document.forms[0].stateProvinceOther.value = "";
			}
		}
	</script>
	</div>

<? include('layout/footer.php'); ?>
